package com.lex.jfb;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by Administrator on 2016/6/3.
 */
public class XG_HMActivity extends BaseActivity {
    private Button countDownBtn;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xiugai_haoma_jifen_bubian);
        findView();
        initView();
    }

    @Override
    protected void findView() {
        countDownBtn = (Button) findViewById(R.id.gain_btn_1);
    }

    @Override
    protected void initView() {
        countDownBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                countdown1();
                countDownBtn.setEnabled(false);
            }
        });
    }

    private void countdown1() {
        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            int time = 10;

            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        time--;
                        if (time <= 0) {
                            timer.cancel();
                            countDownBtn.setText("重新发送");
                            countDownBtn.setEnabled(true);
                        } else {
                            countDownBtn.setText("已发送(" + time + "s)");
                        }
                    }
                });
            }
        }, 0, 1000);
    }
}